﻿class Food {
    private _width: number;
    private _height: number;
    private _position: Point; 

    constructor() {
        this._width = 10;
        this._height = 10;
    }

    drawFood(ctx: CanvasRenderingContext2D): void {
        var oldStyle = ctx.fillStyle;

        ctx.fillStyle = "#FF0000";
        ctx.fillRect(this._position.x, this._position.y
            , this._width, this._height);
        ctx.fillStyle = oldStyle;
    }

    get Position(): Point {
        return this._position;
    }

    set Position(p: Point) {
        this._position = p;
    }

    makePoint(): Point {
        //10的倍数
        let x = 50 + 10 * (Math.floor(40 * Math.random()));
        let y = 50 + 10 * (Math.floor(40 * Math.random()));

        console.log("food x: " + x + ";y: " + y);

        return new Point(x, y);
    }
}